package _75

/*
时间复杂度：O(N)
空间复杂度：O(N)

滑动窗口
*/

func minSwaps(nums []int) int {
	n := len(nums)
	totalOne := 0
	for i := 0; i < n; i++ {
		totalOne += nums[i]
	}
	countOne := 0
	for i := 0; i < totalOne; i++ {
		countOne += nums[i]
	}
	max := countOne
	for i := totalOne; i < n+totalOne; i++ {
		idx := i % n
		countOne += nums[idx] - nums[(i-totalOne)%n]
		if max < countOne {
			max = countOne
		}
	}
	return totalOne - max
}
